package com.itheima_8;

import java.util.Comparator;
import java.util.TreeSet;

public class TreeSetDemo02 {
    public static void main(String[] args) {
        TreeSet<Student> treeSet = new TreeSet<Student>(new Comparator<Student>() {
            @Override
            public int compare(Student s1, Student s2) {
                int num = s1.getAge() - s2.getAge();
                int num2 = num == 0 ? s1.getName().compareTo(s2.getName()) : num;
                return num2;
            }
        });

        Student s1 = new Student("zhangsan",19);
        Student s2 = new Student("lisi",30);
        Student s3 = new Student("wangwu",20);
        Student s4 = new Student("liuliu",50);

        Student s5 = new Student("qiqi",50);
        Student s6 = new Student("qiqi",50);

        treeSet.add(s1);
        treeSet.add(s2);
        treeSet.add(s3);
        treeSet.add(s4);
        treeSet.add(s5);
        treeSet.add(s6);

        for (Student s : treeSet) {
            System.out.println(s.getName()+","+s.getAge());
        }
    }
}
